package cn.kevenpotter.leetcode.easy.e26;

public class RemoveDuplicates {

    public static void main(String[] args) {
        System.out.println(removeDuplicates(new int[]{1, 1, 2}));
    }

    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        if (length == 0) return 0;
        int slowPointer = 0;
        for (int fastPointer = 1; fastPointer < length; fastPointer++) {
            if (nums[fastPointer] != nums[slowPointer]) {
                nums[++slowPointer] = nums[fastPointer];
            }
        }
        return ++slowPointer;
    }
}
